INSERT INTO AssetGroup(Name) VALUES('AllAssets')
GO

INSERT INTO AssetGroup(Name)
SELECT Name
FROM MeterGroup
WHERE Name <> 'AllMeters'
GO

INSERT INTO MeterAssetGroup
SELECT MeterMeterGroup.MeterID, AssetGroup.ID
FROM
    MeterMeterGroup JOIN
    MeterGroup ON MeterMeterGroup.MeterGroupID = MeterGroup.ID JOIN
    AssetGroup ON
        MeterGroup.Name = AssetGroup.Name OR
        (MeterGroup.Name = 'AllMeters' AND AssetGroup.Name = 'AllAssets')
GO

INSERT INTO UserAccountAssetGroup
SELECT UserAccountMeterGroup.UserAccountID, AssetGroup.ID, 1, 1
FROM
    UserAccountMeterGroup JOIN
    MeterGroup ON UserAccountMeterGroup.MeterGroupID = MeterGroup.ID JOIN
    AssetGroup ON
        MeterGroup.Name = AssetGroup.Name OR
        (MeterGroup.Name = 'AllMeters' AND AssetGroup.Name = 'AllAssets')
GO